package com.caocaog.market.entity.dto;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.caocaog.market.entity.GoodsAttr;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * 商品属性数据传输对象
 *
 * @author chechen
 * @date 2022-04-18
 */
@Getter
@Setter
public class GoodsAttrDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "属性id")
    private String id;

    @NotNull(message = "属性名称不能为空")
    @ApiModelProperty(value = "属性名称")
    private String nameSku;

    @NotNull(message = "属性值不能为空")
    @Size(min = 1, message = "至少添加一个属性值")
    @ApiModelProperty(value = "属性值")
    private String[] valueSku;


    public GoodsAttr toGoodsAttr() {
        return new GoodsAttr()
                .setId(this.id)
                .setName(this.nameSku)
                .setValue(StringUtils.join(this.valueSku, StringPool.COMMA));
    }
}
